﻿<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="indexApp">
<head>
    <meta charset="utf-8" />
    <title>内容管理系统</title>

    <link rel="stylesheet" href='@Url.Content("~/Content/css/bootstrap.min.css")' />
    <link rel="stylesheet" href='@Url.Content("~/Content/css/font-awesome.min.css")' />

    <!-- ace styles -->
    <link rel="stylesheet" href='@Url.Content("~/Content/css/ace.min.css")' />
    <link rel="stylesheet" href='@Url.Content("~/Content/css/ace-rtl.min.css")' />
    <link rel="stylesheet" href='@Url.Content("~/Content/css/ace-skins.min.css")' />

    <link rel="stylesheet" href='@Url.Content("~/Content/css/jquery-ui-1.10.3.custom.min.css")' />
    <link rel="stylesheet" href='@Url.Content("~/Content/css/jquery.gritter.css")' />

    <link rel="stylesheet" href='@Url.Content("~/Content/css/busy/ladda-themeless.css")' />
    <link rel="stylesheet" href='@Url.Content("~/Content/css/busy/gbtags.css")' />

    <script src='@Url.Content("~/Content/js/respond.min.js")'></script>
    <script src='@Url.Content("~/Content/js/bootstrap-2.3.2/placeholders.js")'></script>

</head>

<body ng-controller="indexController">

    <div style="background: url(BG.jpg) top center repeat-y #B1B1B1; position: fixed; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 9999; text-align: center;" ng-class="isLoading?'':'modal'">
        <div style="height: 137px; margin-top: 100px;">
            <img src="loaded.gif" width="384" height="137" />
        </div>
        <div style="padding-top: 48px; height: 36px;">
            <img src="loding.gif" width="238" height="36" />
        </div>
        <div style="font: bold 12px/12 '宋体'; color: #666;">{{loadingText}}</div>
    </div>

    <div class="navbar navbar-default" id="navbar">
        <script type="text/javascript">
            try { ace.settings.check('navbar', 'fixed') } catch (e) { }
        </script>

        <div class="navbar-container" id="navbar-container">

            <div class="navbar-header pull-left" style="padding-top: 2px">
                <img src="{{appItem.icon}}" style="height: 40px; width: 40px;" />
            </div>

            <div class="navbar-header pull-left">
                <a href="#" class="navbar-brand">
                    <small>
                        {{appItem.name}}
                    </small>
                </a>
                <!-- /.brand -->
            </div>

            <!-- /.navbar-header -->

            <div class="navbar-header pull-right" role="navigation" ng-mouseover="g_timer.onPause()" ng-mouseleave="g_timer.onResume()">
                <ul class="nav ace-nav">
                    <li class="grey" ng-style="{display: isDisplay(enabelNotification)}">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-tasks"></i>
                            <span class="badge badge-grey">{{taskItem.totalCount}}</span>
                        </a>
                        <ul class="pull-right dropdown-navbar dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header">
                                <i class="icon-ok"></i>
                                还有{{taskItem.unRead}}个任务完成
                            </li>

                            <li ng-repeat="taskInfo in taskList">
                                <a href="#">
                                    <div class="clearfix">
                                        <span class="pull-left">{{taskInfo.title}}</span>
                                        <span class="pull-right">{{taskInfo.progress}}</span>
                                    </div>

                                    <div class="progress progress-mini ">
                                        <div ng-style="{width: taskInfo.progress}" class="progress-bar "></div>
                                    </div>
                                </a>
                            </li>

                            <li>
                                <a href="#">
                                    查看任务详情
                                    <i class="icon-arrow-right"></i>
                                </a>
                            </li>
                        </ul>
                    </li>

                    <li class="purple" ng-style="{display: isDisplay(enabelNotification)}">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-bell-alt"></i>
                            <!--<i ng-class="alertItem.totalCount>0?'icon-bell-alt icon-animated-bell':'icon-bell-alt'"></i>-->
                            <span class="badge badge-important">{{alertItem.totalCount}}</span>
                        </a>

                        <ul class="pull-right dropdown-navbar navbar-pink dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header">
                                <i class="icon-warning-sign"></i>
                                {{alertItem.unRead}}条通知
                            </li>

                            <li ng-repeat="alertInfo in alertList">
                                <a href="#">
                                    <div class="clearfix">
                                        <span class="pull-left">
                                            <i class="btn btn-xs no-hover btn-pink icon-comment"></i>
                                            {{alertInfo.title}}
                                        </span>
                                        <span class="pull-right badge badge-info">+ {{alertInfo.count}}</span>
                                    </div>
                                </a>
                            </li>

                            <li>
                                <a href="#">
                                    查看所有通知
                                    <i class="icon-arrow-right"></i>
                                </a>
                            </li>
                        </ul>
                    </li>

                    <li class="green" ng-style="{display: isDisplay(enabelNotification)}">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-envelope"></i>
                            <!-- <i ng-class="messItem.totalCount>0?'icon-envelope icon-animated-vertical':'icon-envelope'"></i>-->
                            <span class="badge badge-success">{{messItem.totalCount}}</span>
                        </a>

                        <ul class="pull-right dropdown-navbar dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header">
                                <i class="icon-envelope-alt"></i>
                                {{messItem.unRead}}条消息
                            </li>

                            <li ng-repeat="messInfo in messList">
                                <a href="#">
                                    <span class="msg-body">
                                        <span class="msg-title">
                                            <span class="blue">
                                                <i class="btn btn-xs no-hover btn-pink icon-comment"></i>
                                                {{messInfo.senderText}}
                                            </span>
                                            {{messInfo.title}}
                                        </span>

                                        <span class="msg-time">
                                            <i class="icon-time"></i>
                                            <span>{{messInfo.createdTime}}</span>
                                        </span>
                                    </span>
                                </a>
                            </li>

                            <li>
                                <a href="inbox.html">
                                    查看所有消息
                                    <i class="icon-arrow-right"></i>
                                </a>
                            </li>
                        </ul>
                    </li>

                    <li class="light-blue">
                        <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                            <img class="nav-user-photo" src="{{userItem.avatar}}" />
                            <span class="user-info">
                                <small>欢迎光临,</small>
                                {{userItem.name}}
                            </span>

                            <i class="icon-caret-down"></i>
                        </a>

                        <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                            <li ng-repeat="action in userItem.actions">
                                <a href="{{action.url}}">
                                    <i class="{{action.icon}}"></i>
                                    {{action.caption}}
                                </a>
                            </li>

                            <li>
                                <a href="#" ng-click="onLogOut()">
                                    <i class="icon-off"></i>
                                    退出
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <!-- /.ace-nav -->
            </div>
            <!-- /.navbar-header -->
        </div>
        <!-- /.container -->
    </div>

    <div class="main-container" id="main-container">
        <script type="text/javascript">
            try { ace.settings.check('main-container', 'fixed') } catch (e) { }
        </script>

        <div class="main-container-inner">
            <a class="menu-toggler" id="menu-toggler" href="#">
                <span class="menu-text"></span>
            </a>

            <div class="sidebar" id="sidebar">
                <script type="text/javascript">
                    try { ace.settings.check('sidebar', 'fixed') } catch (e) { }
                </script>

                <div class="sidebar-shortcuts" id="sidebar-shortcuts" style="max-height: none;">
                    <div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large" ng-style="{display: isDisplay(enableShortcut)}">
                        <button class="btn btn-success">
                            <i class="icon-signal"></i>
                        </button>

                        <button class="btn btn-info">
                            <i class="icon-pencil"></i>
                        </button>

                        <button class="btn btn-warning">
                            <i class="icon-group"></i>
                        </button>

                        <button class="btn btn-danger">
                            <i class="icon-cogs"></i>
                        </button>
                    </div>

                    <div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
                        <span class="btn btn-success"></span>

                        <span class="btn btn-info"></span>

                        <span class="btn btn-warning"></span>

                        <span class="btn btn-danger"></span>
                    </div>
                </div>
                <!-- #sidebar-shortcuts -->
                <div>
                    <ul class="nav nav-list">
                        <li ng-repeat="item in items" ng-class="{active:item.isActive}">

                            <a class="dropdown-toggle" href="#" ng-click="onNavItemClick(item,item.linkUrl)">
                                <i class="icon-file-alt"></i>
                                <span class="menu-text">{{item.caption}} </span>
                                <b class="arrow icon-angle-down" ng-style="{visibility: hasSubItems(item)}"></b>
                            </a>

                            <ul class="submenu" ng-style="{visibility: hasSubItems(item)}">
                                <li ng-repeat="subItem in item.items" ng-class="{active:subItem.isActive}">
                                    <a href="#" ng-click="onNavItemClick(subItem,subItem.linkUrl)" class="dropdown-toggle">
                                        <i class="icon-double-angle-right"></i>
                                        {{subItem.caption}}
                                        <b class="arrow icon-angle-down" ng-style="{visibility: hasSubItems(subItem)}"></b>
                                    </a>

                                    <ul class="submenu" ng-style="{visibility: hasSubItems(subItem)}">
                                        <li ng-repeat="thirdLevelItem in subItem.items" ng-class="{active:thirdLevelItem.isActive}">
                                            <a href="#" ng-click="onNavItemClick(thirdLevelItem,thirdLevelItem.linkUrl)" class="dropdown-toggle">
                                                <i class="icon-leaf"></i>
                                                {{thirdLevelItem.caption}}
                                                <b class="arrow icon-angle-down"></b>
                                            </a>

                                        </li>
                                     </ul>
                                </li>
                            </ul>
                        </li>

                    </ul>

                </div>
                <!-- /.nav-list -->
                <!-- <div class="sidebar-collapse" id="sidebar-collapse">
                    <i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
                </div>-->

                <script type="text/javascript">
                    try { ace.settings.check('sidebar', 'collapsed') } catch (e) { }
                </script>
            </div>

            <div class="main-content">
                <div class="breadcrumbs" id="breadcrumbs">
                    <script type="text/javascript">
                        try { ace.settings.check('breadcrumbs', 'fixed') } catch (e) { }
                    </script>

                    <ul class="breadcrumb">
                        <li>
                            <i class="icon-home home-icon"></i>
                            <a href="#">首页</a>{{pageTitle}}
                        </li>

                    </ul>
                    <!-- .breadcrumb -->

                    <div class="nav-search" id="nav-search">
                        <form class="form-search">
                            <span class="input-icon">
                                <input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
                                <i class="icon-search nav-search-icon"></i>
                            </span>
                        </form>
                    </div>
                    <!-- #nav-search -->
                </div>

                <div class="page-content">
                    <div class="page-header">
                        <h1 id="h_title">
                            {{pageTitle}}
                            <small>
                                <i class="icon-double-angle-right"></i>
                                查看
                            </small>
                        </h1>
                    </div>
                    <!-- /.page-header -->
                    <div class="row">
                        <div class="col-xs-12">
                            <div id="iframeContainer">
                                <iframe id="iframcontrol" name="iframcontrol" src="Module/cms/index.html" style="width: 100%; height: 100%;" frameborder="no" border="0"></iframe>
                            </div>

                        </div>
                    </div>

                    <!-- /.row -->
                </div>

                <!-- /.page-content -->
            </div>
            <!-- /.main-content -->
            <!-- /#ace-settings-container -->
        </div>
    </div>
    <!-- /.main-container -->

    <script type="text/javascript" src='@Url.Content("~/Config.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/jquery-1.10.2/jquery-1.10.2.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/bootstrap.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/typeahead-bs2.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/ace.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/ace-elements.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/bootbox.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/promise/promise.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/jquery.gritter.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/angular-1.2.29/angular-1.2.29.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/jquery.cookie.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/bootstrap/jquery.bootstrap-growl.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/busy/jquery.jribbble.min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/busy/spin.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/busy/ladda.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/blockui/jquery.blockUI.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/js/cppei/cppei.frame.js")'></script>
    <script>
        cppei.install('iframcontrol');

        var storage = window.localStorage;

        function timer(func) {
            this.handle = null;
            this.isPause = false;
            this.func = func;
            this.start = function () {
                // console.log('timer is start');
                if (!this.handle) {
                    this.handle = window.setInterval(function (inst) {
                        inst.onTick();
                    }, 10000, this);
                    //this.handle = window.setInterval(func, 1000);
                    // document.getElementById('output').innerHTML += 'start:' + this.handle + '<br/>';
                }

            }
            this.onTick = function () {
                if (!this.isPause) {
                    if (this.func) {
                        this.func();
                    }
                }
            }
            this.onStop = function () {
                if (this.handle) {
                    window.clearInterval(this.handle);
                    this.handle = null;
                }
            }
            this.onPause = function () {
                // console.log('timer is pause');
                this.isPause = true;
            }
            this.onResume = function () {
                //  console.log('timer is begin');
                this.isPause = false;
            }
        }

        var app = angular.module('indexApp', []);
        app.controller("indexController", function ($scope, $http, $q) {

            $scope.isLoading = false;
            $scope.loadingText = "正在加载信息...";
            $scope.enabelNotification = xweb.enabelNotification;//是否启用通知
            $scope.enableShortcut = xweb.enableShortcut;//是否启用快捷方式

            //获取标题和图标
            $scope.appItem = {};
            $scope.appItem.icon = xweb.logo;
            $scope.appItem.name = xweb.title;

            //获取左侧菜单列表
            $scope.getNavList = function () {
                $scope.loadingText = "正在加载左侧菜单列表...";
                // console.log($scope.loadingText);
                var prms = Promise();

                // console.log('$scope.getList begin');
                $http({
                    method: 'get',
                    url: jframe.getUrl('Api/Menu/List')
                }).success(function (result) {
                    if (result.isSuccess) {
                        //   console.log('$scope.getList success');
                        if (result.data != null) {
                            $scope.items = result.data.items;
                            $scope.addActive($scope.items);
                        } else {
                            $scope.items = {};
                        }

                        prms.resolve();
                    }
                    else {
                        //console.log('$scope.getList failure');
                        prms.reject();
                    }

                }).error(function (result, status) {
                    // console.log('$scope.getList error');
                    prms.reject();
                });
                return prms;
            }

            //获取用户信息
            $scope.getUserProfile = function () {
                $scope.loadingText = "正在加载用户信息...";
                // console.log($scope.loadingText);
                var prms = Promise();

                // console.log('$scope.getUserProfile begin');
                $http({
                    method: 'get',
                    url: jframe.getUrl('api/user/profile')
                }).success(function (result, status) {
                    //debugger;
                    if (result.isSuccess) {
                        //  console.log('$scope.getUserProfile success');
                        $scope.userItem = {};
                        $scope.userItem.avatar = result.data.avatar;
                        $scope.userItem.name = result.data.name;
                        $scope.userItem.userId = result.data.userId;
                        $scope.userItem.actions = result.data.actions;

                        angular.forEach($scope.userItem.actions, function (data) {
                            if (data.icon == null) {
                                data.icon = 'icon-cog';
                            }
                        });

                        storage["userName"] = $scope.userItem.name;
                        storage["userId"] = $scope.userItem.userId;

                        prms.resolve();
                    }
                    else {
                        //  console.log('$scope.getUserProfile failure');
                        prms.reject();
                    }

                }).error(function (result, status) {
                    // console.log('$scope.getUserProfile error');
                    prms.reject();
                });
                return prms;
            }

            //如果获取列表等信息失败，则返回登录页
            $scope.returnLogin = function () {
                // console.log('$scope.returnLogin');
                //window.location.href = jframe.getUrl('Account/Login');
            }

            //设置遮幕
            $scope.isFullVisible = function () {

                $scope.isLoading = false;

                if (xweb.isRefresh) {
                    $scope.g_timer.start();
                }
            }


            //顺序执行获取列表信息等事件
            $scope.getUserProfile()
                .then($scope.getNavList, $scope.returnLogin)
                .then($scope.isFullVisible, $scope.returnLogin);

            //左侧菜单活动的叶子节点
            $scope.activedLeafNode = null;

            //是否为活动的节点
            $scope.checkActiveStatus = function (item) {
                if ($scope.activedLeafNode == item) {
                    return true;
                }
                return false;
            }

            //给数组每一项（子项）加上isactive属性
            $scope.addActive = function (itemArr) {
                //debugger;

                var isNull = $scope.checkItemsLength(itemArr);

                if (isNull) {
                    angular.forEach(itemArr, function (data) {
                        if (data != $scope.activedLeafNode) {
                            data.isActive = false;
                        } else {
                            data.isActive = true;
                        }
                        $scope.addActive(data.items);
                        //  console.log(data.Active);
                    });

                } else {
                    return;
                }
            }

            //判断数组是否为空，itemArr为需要判断数组，若为空返回false，不为空返回true
            $scope.checkItemsLength = function (itemArr) {
                // debugger;
                if (itemArr == null || itemArr.length == 0) {
                    return false;
                } else {
                    return true;
                }
            }

            // 从导航链接上点击
            $scope.onNavItemClick = function (currItem, ifreamScr) {
                if (currItem.items != null && currItem.items.length > 0) {
                    return;
                }

                $scope.activedLeafNode = currItem;

                $scope.addActive($scope.items);

                var rootItems = $scope.items;

                var returnPath = [];
                $scope.traverseMenuItems(rootItems, currItem, returnPath);
                //debugger;
                angular.forEach(returnPath, function (data) {
                    data.isActive = true;
                });

                if (cppei.switchView(ifreamScr)) {
                    $scope.pageTitle = currItem.caption;
                }
            }

            //查找活动节点的路径
            $scope.traverseMenuItems = function (rootItems, curItem, returnPath) {
                for (var index = 0; index < rootItems.length; index++) {
                    if (rootItems[index] == curItem) {
                        // find
                        returnPath.push(rootItems[index]);
                        return true;
                    } else {
                        if (rootItems[index].items != null && rootItems[index].items.length > 0) {
                            // has children in this item
                            returnPath.push(rootItems[index]);
                            var isFound = $scope.traverseMenuItems(rootItems[index].items, curItem, returnPath);
                            if (isFound) {
                                return true;
                            }
                        }
                    }
                }
                returnPath.pop();
                return false;
            }

            //
            $scope.hasSubItems = function (item) {
                //debugger;
                if (item.items == null || item.items.length == 0) {
                    return 'hidden';
                } else {
                    return 'visible';
                }
            }

            //
            $scope.hasSubItems2Bool = function (item) {
                //debugger;
                if (item.items == null || item.items.length == 0) {
                    return false;
                } else {
                    return true;
                }
            }

            //
            $scope.isDisplay = function (flag) {
                if (flag) {
                    return 'block';
                } else {
                    return 'none';
                }

            }

            //退出
            $scope.onLogOut = function () {
                $http({
                    method: 'post',
                    url: postUrlWithTimespan('user/quit')
                    // data: {}
                }).success(function (result, status) {
                    if (result.isSuccess) {
                        window.location.href = "login.html";
                    }
                }).error(function (result, status) {
                    cppei.growl(result.message);
                });

            }

            //获取信息(暂时没做)
            $scope.getMessage = function () {
                //  console.log('$scope.getMessage begin');
                $http({
                    method: 'get',
                    url: getUrlWithTimespan('user/message')
                }).success(function (result, status) {
                    if (result.isSuccess) {
                        //var time = new Date().getSeconds();
                        //var testList = [{ from: 'Tom', title: 'test1', num: '65%' },
                        //{ from: 'John', title: 'testTitlr1', num: '40%' },
                        //{ from: 'Lily', title: 'testsss1', num: '80%' } ];
                        // console.log('$scope.getMessage success');
                        $scope.taskItem = {};
                        $scope.taskItem.totalCount = result.data.task.totalCount;
                        $scope.taskItem.unRead = result.data.task.unreadCount;
                        $scope.taskList = result.data.task.items;//id,title,isRead,progress,createdTime
                        angular.forEach($scope.taskList, function (value) {
                            value.progress = value.progress + '%';
                        });

                        $scope.alertItem = {};
                        $scope.alertItem.totalCount = result.data.alert.totalCount;
                        $scope.alertItem.unRead = result.data.alert.unreadCount;
                        $scope.alertList = result.data.alert.items; //id,title,isRead,count,createdTime

                        $scope.messItem = {};
                        $scope.messItem.totalCount = result.data.message.totalCount;
                        $scope.messItem.unRead = result.data.message.unreadCount;
                        $scope.messList = result.data.message.items; //id,title,isRead,senderId,senderText,createdTime
                    }
                    else {
                        //  console.log('$scope.getMessage failure');
                        prms.reject();
                    }
                }).error(function (result, status) {
                    // console.log('$scope.getMessage error');
                });

            }

            //定时刷新(暂时没做)
            $scope.g_timer = new timer(function () {
                $scope.$apply(function () {
                    $scope.getMessage();
                });
            });
        });
</script>

</body>
</html>


